//
//  AddressBookTableViewCell.m
//  chongwu
//
//  Created by 隼目 on 2021/9/16.
//

#import "AddressBookTableViewCell.h"

@implementation AddressBookTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(void)creatCellView{
   self.backgroundColor=[UIColor clearColor];
    
   AddressModel *model=[AddressModel mj_objectWithKeyValues:self.cellDic];
    
   UIView *centerView=[UIView new];
   [self.contentView addSubview:centerView];
   [centerView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.mas_equalTo(30*_mainWidth);
      make.right.mas_equalTo(-30*_mainWidth);
      make.top.mas_equalTo(10*_mainHeight);
      make.bottom.mas_equalTo(-10*_mainHeight);
   }];
   centerView.backgroundColor=[UIColor whiteColor];
   centerView.layer.cornerRadius=25*_mainWidth;
    
    
   UIView *xianView=[UIView new];
   [centerView addSubview:xianView];
   [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.left.mas_equalTo(30*_mainWidth);
       make.right.mas_offset(-30*_mainWidth);
       make.height.mas_equalTo(1*_mainHeight);
       make.bottom.mas_equalTo(-87*_mainWidth);
   }];
   xianView.backgroundColor=rgba(232,232,232,1);
    
    
   UIView *topView=[UIView new];
   [centerView addSubview:topView];
   [topView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.right.top.mas_equalTo(0);
      make.bottom.mas_equalTo(xianView.mas_top);
   }];
    
   UILabel *nameLabel=[UILabel new];
   [topView addSubview:nameLabel];
   [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.mas_equalTo(40*_mainWidth);
      make.top.mas_equalTo(33*_mainHeight);
   }];
   [nameLabel layoutIfNeeded];
   nameLabel.text=model.addressUsername?model.addressUsername:@"";
   nameLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(36)];
   nameLabel.textColor=rgba(47,47,47,1);
   
   UILabel *phoneLabel=[UILabel new];
   [topView addSubview:phoneLabel];
   [phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.mas_equalTo(nameLabel.mas_right).mas_equalTo(25*_mainWidth);
      make.centerY.mas_equalTo(nameLabel);
      make.right.mas_equalTo(-89*_mainWidth);
   }];
   [phoneLabel layoutIfNeeded];
   phoneLabel.text=model.addressPhone?model.addressPhone:@"";
   phoneLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(28)];
   phoneLabel.textColor=rgba(102,102,102,1);
    
   UILabel *addressLabel=[UILabel new];
   [topView addSubview:addressLabel];
   [addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.mas_equalTo(40*_mainWidth);
      make.right.mas_equalTo(phoneLabel);
      make.top.mas_equalTo(nameLabel.mas_bottom).mas_equalTo(8*_mainHeight);
   }];
   [addressLabel layoutIfNeeded];
   addressLabel.numberOfLines=0;
   addressLabel.text=[NSString stringWithFormat:@"%@%@%@%@",model.addressProvincial?model.addressProvincial:@"",model.addressCity?model.addressCity:@"",model.addressArea?model.addressArea:@"",model.addressDetail?model.addressDetail:@""];
   addressLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(28)];
   addressLabel.textColor=rgba(47,47,47,1);
    
   UIButton *btn=[UIButton new];
   [topView addSubview:btn];
   [btn mas_makeConstraints:^(MASConstraintMaker *make) {
      make.centerY.mas_equalTo(0);
      make.width.mas_equalTo(30*_mainWidth);
      make.height.mas_equalTo(33*_mainWidth);
      make.right.mas_equalTo(-40*_mainWidth);
   }];
   [btn setImage:[UIImage imageNamed:@"bianji"] forState:0];
   [btn addTarget:self action:@selector(pushToControllerBtn) forControlEvents:UIControlEventTouchUpInside];
   UIView *bottomView=[UIView new];
   [centerView addSubview:bottomView];
   [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.right.bottom.mas_equalTo(0);
      make.top.mas_equalTo(xianView.mas_bottom);
   }];
    
   UIButton *agreementBtn=[UIButton new];
   [bottomView addSubview:agreementBtn];
   [agreementBtn mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.mas_equalTo(41*_mainWidth);
      make.centerY.mas_equalTo(0);
      make.width.height.mas_equalTo(18*_mainWidth);
   }];
   if (model.defaultAddress) {
      [agreementBtn setImage:[UIImage imageNamed:@"xuanzhong"] forState:0];
   }else{
      [agreementBtn setImage:[UIImage imageNamed:@"weixuanzhong"] forState:0];
   }
   [agreementBtn addTarget:self action:@selector(selectAgreementBtn) forControlEvents:UIControlEventTouchUpInside];
    
   UILabel *label=[UILabel new];
   [bottomView addSubview:label];
   [label mas_makeConstraints:^(MASConstraintMaker *make) {
      make.left.mas_equalTo(73*_mainWidth);
      make.centerY.mas_equalTo(0);
      make.right.mas_equalTo(-150*_mainWidth);
      make.height.mas_equalTo(36*_mainHeight);
   }];
   label.text=@"设为默认寄件地址";
   label.textColor=rgba(144,149,165,1);
   label.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(25)];
   label.userInteractionEnabled=YES;
   UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectAgreementBtn)];
   [label addGestureRecognizer:tapGesture];
   
   UIButton *deleteBtn=[UIButton new];
   [bottomView addSubview:deleteBtn];
   [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
      make.right.mas_equalTo(-40*_mainWidth);
      make.centerY.mas_equalTo(0);
      make.width.mas_equalTo(80*_mainWidth);
      make.height.mas_equalTo(50*_mainHeight);
   }];
   [deleteBtn setTitle:@"删除" forState:0];
   [deleteBtn setTitleColor:rgba(102,102,102,1) forState:0];
   deleteBtn.titleLabel.font=[UIFont fontWithName:@"PingFang SC" size:autoScaleW(25)];
   deleteBtn.titleLabel.textAlignment=NSTextAlignmentRight;
   [deleteBtn addTarget:self action:@selector(selectDeleteBtn) forControlEvents:UIControlEventTouchUpInside];

}
-(void)selectAgreementBtn{
   if (self.delegate!=nil) {
      [self.delegate selectAgreement:self.cellDic];
   }
}
-(void)selectDeleteBtn{
   
   if (self.delegate!=nil) {
      [self.delegate selectDelete:self.cellDic];
   }
}
-(void)pushToControllerBtn{
   if (self.delegate!=nil) {
      [self.delegate pushToController:self.cellDic];
   }
}
@end
